/**
 * 快速排序最简版
 * @param {number[]} nums
 * @return {number[]}
 */

const quickSort = arr => {
  if (arr.length < 2) return arr

  const mid = ~~(arr.length / 2)
  const pivod = arr[mid],
    left = arr.filter((num, index) => {
      if (index !== mid) {
        return num <= pivod
      }
    }),
    right = arr.filter(num => num > pivod)

  return [...quickSort(left), pivod, ...quickSort(right)]
}

const sortArray = nums => {
  return quickSort(nums)
}

console.log(sortArray([1, 5, 4, 2, 3]))